<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义Js对象</title>
</head>
<body>
    <table border="1px">
        <tr>
            <th><b>商品标题</b></th>
            <th><b>商品价格</b></th>
            <th><b>商品库存</b></th>
        </tr>
    </table>
<script>
    let productArr = [
        {title: '小米14' ,price: 8000,num: 200},
        {title: '华为Mate60',price: 5000,num: 100},
        {title: '苹果16' ,price: 10000,num: 700},
        {title: '魅族' ,price: 2000,num: 600}
    ];
    console.log(productArr);

    for (let i = 0; i < productArr.length; i++) {
        // 创建一个tr，三个td
        let tr = document.createElement('tr');
        let titleTd = document.createElement('td');
        let priceTd = document.createElement('td');
        let numTd = document.createElement('td');
        // 将数组中的数据添加到td中
        titleTd.innerHTML = productArr[i].title;
        priceTd.innerHTML = productArr[i].price;
        numTd.innerHTML = productArr[i].num;
        //再将td添加到tr中
        tr.append(titleTd, priceTd, numTd);
        //再将tr添加到table中
        document.querySelector('table').append(tr);
    }

    let p1 = {
        name:'张三',
        age:18,
        say:function(){
            console.log('我是'+this.name+',今年'+this.age+'岁');
        }
    };
    console.log(p1);
    p1.say();
</script>


</body>
</html>